<?php

/**
 * main actions.
 *
 * @package    explications_informatiques
 * @subpackage contact
 * @author     Guimezanes Cyrille
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contactActions extends sfActions
{
/**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
	  $this->forwardUnless($this->getUser()->isAuthenticated() && $this->getUser()->hasCredential("CAN_CONTACT"),"headers","forbidden");
	  $this->form = new ContactsForm();
  }
  public function executeDocontact(sfWebRequest $request)
  {
    $this->forwardUnless($this->getUser()->isAuthenticated() && $this->getUser()->hasCredential("CAN_CONTACT"),"headers","forbidden");
	$this->forwardUnless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT),"headers","forbidden");
    $this->form = new ContactsForm();
    $this->processFormContact($request, $this->form);
    $this->setTemplate('index');
  }
  protected function processFormContact(sfWebRequest $request, sfForm $form)
  {
	  $this->forwardUnless($this->getUser()->isAuthenticated() && $this->getUser()->hasCredential("CAN_CONTACT"),"headers","forbidden");
	  $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
	  if($form->isValid())
		{
			
			$message = $this->getMailer()->compose(
				  array('contact@explications-informatiques.fr' => "L'équipe d'explications-informatiques.fr"),
				  "",
				  '[EI][CONTACT]['.$this->getUser()->getGuardUser()->getId().']['.$this->getUser()->getGuardUser()->getUserName().'] '.$request["contact"]["raison"],
					$request["contact"]["texte"]
				);
 
    		$this->getMailer()->send($message);
			$this->getUser()->setFlash("info","Votre message à été envoyé à notre équipe. Il sera traité rapidement :) ");
		}
		//log
		sfCoreAutoload::logElem("Prise de contact", $this->getUser()->getGuardUser()->getId(), date("Y-m-d h:i:s"));
		$this->redirect("contact/index");
  }
}?>